package com.example.brainmemory.engine;

import java.util.ArrayList;

public class Numbers {

	int number, maxNumber, minNumber = 0;
	private ArrayList<Integer> randomNumbners = new ArrayList<Integer>();

	public Numbers(int number, int minNumber, int maxNumber) {
		this.number = number;
		this.minNumber = minNumber;
		this.maxNumber = maxNumber;
	}

	/*
	 * remove all old numbers (with a hammer) an call a method wich make new
	 * numbers
	 */
	public ArrayList<Integer> getForcedRandomNumbers() {
		randomNumbners = null;
		return getRandomNumbers();
	}

	/*
	 * This method returns a random number between the min- and the maximum.
	 * 
	 * TODO: Find a correct implementation for this case. The actual
	 * implementation return values over the maximum.
	 */
	private int getRandomNumber() {
		return (int) Math.round(Math.random() * maxNumber + minNumber);
	}

	/*
	 * Returns the list of randomnumbers if this list exists. Else it create one
	 * and return the new list.
	 */
	public ArrayList<Integer> getRandomNumbers() {
		if (randomNumbners != null && randomNumbners.size() == number)
			return randomNumbners;

		randomNumbners = new ArrayList<Integer>();
		for (int i = 0; i < number; i++) {
			while (true) {
				int tmp = getRandomNumber();
				if (randomNumbners.contains(tmp)) {
					continue;
				} else {
					randomNumbners.add(tmp);
					break;
				}
			}

		}

		return randomNumbners;
	}
}
